using UnityEngine;
using System.Collections;

[System.Serializable]
public class DrawCursor : MonoBehaviour {
	
	public Texture2D mouseCursorTexture;
	
	/**
	 * http://answers.unity3d.com/questions/145024/unity3d-custom-cursors.html
	 * Adapted to C# by André Nilsen
	 * */
	
	public int cursorSizeX = 16;  // Your cursor size x
	public int cursorSizeY = 16;
	
	private Rect cursorPosition;
	
	// Use this for initialization
	void Start () {
		//cursorPosition = new Rect(Event.current.mousePosition.x-cursorSizeX/2, Event.current.mousePosition.y-cursorSizeY/2, cursorSizeX, cursorSizeY);
		
		cursorPosition = new Rect(Screen.width/2-cursorSizeX/2, Screen.height/2-cursorSizeY/2, cursorSizeX, cursorSizeY);
		
		Screen.showCursor = false;
		Screen.lockCursor = false;
		
	}
	
	// Update is called once per frame
	void Update () {
		Screen.lockCursor = !Game.game.inventoryShown;
		//Screen.lockCursor = false;
		cursorPosition = new Rect(Input.mousePosition.x, Screen.height-Input.mousePosition.y, cursorSizeX, cursorSizeY);
		//Debug.Log("Cursor x: " + cursorPosition.x + ", Cursor y: " + cursorPosition.y);
	}
	
	void OnGUI()
	{
	    GUI.DrawTexture (cursorPosition, mouseCursorTexture);
	}
}
